package com.tuanbiao.keyevent;

import android.os.Build;

import com.tuanbiao.keyevent.listener.OnBlastKeyDownListener;
import com.tuanbiao.keyevent.listener.OnBlastNettedKeyDownListener;
import com.tuanbiao.keyevent.listener.OnKeyDownListener;
import com.tuanbiao.keyevent.listener.OnLoginKeyDownListener;
import com.tuanbiao.keyevent.listener.OnSettingKeyDownListener;

import java.util.List;

import timber.log.Timber;

/**
 * @author abiao
 * @date 2022/6/6 15:23
 * @description:
 */
public class KeyEventHelper implements KeyEventStrategy {
    private static volatile KeyEventHelper INSTANCE;
    private KeyEventStrategy strategy = new UrovoKeyEvent();

    public static KeyEventHelper getInstance() {
        if (null == INSTANCE) {
            synchronized (KeyEventHelper.class) {
                if (null == INSTANCE) {
                    INSTANCE = new KeyEventHelper();
                }
            }
        }
        return INSTANCE;
    }

    private KeyEventHelper() {

    }

    public void init() {
        String model = Build.BRAND.toLowerCase();
        Timber.i("init#model:" + model);
        switch (model) {
            case "alps":
                setKeyEventStrategy(new AlpsKeyEvent());
                break;
            case "lxr":
                setKeyEventStrategy(new LXRKeyEvent());
                break;
            case "urovo":
                setKeyEventStrategy(new UrovoKeyEvent());
                break;
            default:
                setKeyEventStrategy(new UrovoKeyEvent());
                break;
        }
    }

    public void setKeyEventStrategy(KeyEventStrategy strategy) {
        this.strategy = strategy;
    }

    @Override
    public void checkLoginKeyDown(int keyCode, OnLoginKeyDownListener listener) {
        strategy.checkLoginKeyDown(keyCode, listener);
    }

    @Override
    public String getChargeNoteSuccess() {
        return strategy.getChargeNoteSuccess();
    }

    @Override
    public String getChargeNoteFailed() {
        return strategy.getChargeNoteFailed();
    }

    @Override
    public String getChargeNoteFailed(String msg) {
        return strategy.getChargeNoteFailed(msg);
    }

    @Override
    public String getBlastNoteSuccess() {
        return strategy.getBlastNoteSuccess();
    }

    @Override
    public String getBlastNoteFailed() {
        return strategy.getBlastNoteFailed();
    }

    @Override
    public String getBlastNoteFailed(String msg) {
        return strategy.getBlastNoteFailed(msg);
    }

    @Override
    public List<Integer> getScanModeKeys() {
        return strategy.getScanModeKeys();
    }

    @Override
    public void checkBlastKeyDown(int keyCode, OnBlastKeyDownListener listener) {
        strategy.checkBlastKeyDown(keyCode, listener);
    }

    @Override
    public String getNettedNoteSuccess() {
        return strategy.getNettedNoteSuccess();
    }

    @Override
    public String getNettedNoteFailed() {
        return strategy.getNettedNoteFailed();
    }

    @Override
    public void checkBlastNettedKeyDown(int keyCode, OnBlastNettedKeyDownListener listener) {
        strategy.checkBlastNettedKeyDown(keyCode, listener);
    }

    @Override
    public void checkSettingKeyDown(int keyCode, OnSettingKeyDownListener listener) {
        strategy.checkSettingKeyDown(keyCode, listener);
    }

    @Override
    public void checkUploadDataKeyDown(int keyCode, OnKeyDownListener listener) {
        strategy.checkUploadDataKeyDown(keyCode, listener);
    }

    @Override
    public void checkUploadDataDetailsKeyDown(int keyCode, OnKeyDownListener listener) {
        strategy.checkUploadDataDetailsKeyDown(keyCode, listener);
    }

    @Override
    public void aboutKeyDown(int keyCode, OnKeyDownListener listener) {
        strategy.aboutKeyDown(keyCode, listener);
    }
}
